package com.jxc.servlet.Session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/Session/SessionLogin")
public class SessionLoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().print("<h1 style='text-align:center'>user login successful!</h1>");
        // 获取用户会话session对象
        HttpSession session= req.getSession();
        // 将用户数据储存到session里
        session.setAttribute("user","jxc");
        // 请求转发
        req.getRequestDispatcher("/Session/SessionIndex").forward(req,resp);
    }
}
